<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class CarSeat_m extends MY_Model
{

    const TBL = 'car_seat';

    function __construct()
    {
        parent::__construct();
    }

    public function get_car_level()
    {
        return [
            '1' => "舒适型",
            '2' => "豪华型",
        ];
    }

    public function count_seats()
    {
        $this->db->select('*');
        $this->db->from('car_seat');
        $total = $this->db->count_all_results();
        return $total;
    }

    //翻页及搜索
    public function get_seats_list($start, $limit)
    {
        $this->db->select('*');
        $this->db->from('car_seat');
        $this->db->order_by("car_level", 'asc');
        $this->db->limit($limit, $start);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
    }

    public function get_seat_ids_by_pasengers($pasengers)
    {
        $this->db->select('id');
        $this->db->from('car_seat');
        $this->db->where('car_seat >=', $pasengers);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
    }

    public function get_car_by_car_requirement($car_level, $car_seat)
    {
        $this->db->select('id');
        $this->db->from('car_seat');
        $this->db->group_start();
        $this->db->where('car_level >=', $car_level);
        $this->db->where('car_seat >=', $car_seat);
        $this->db->group_end();
        $this->db->or_group_start();
        $this->db->where('car_seat >', $car_seat);
        $this->db->group_end();
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
    }
}
